const chalk = require("chalk");
const program = require("commander");
const event = process.env.npm_lifecycle_event;
const scripts = process.env.npm_lifecycle_script;
const VueCreator = require("./create.js");
const Deploy = require("./deploy.js");
const Storage = require("./storage.js");

let scriptString;
let scriptsArray = [];
if (scripts.length === scripts.indexOf(".js") + 3) {
	scriptString = "test";
} else {
	scriptString = scripts.substring(scripts.indexOf(".js") + 3, scripts.length).trim().replace(/"/g, "");
	scriptsArray = scriptString.split(" ");
}

let filePath = scriptsArray.length > 1 ? scriptsArray[0] + "/" + scriptsArray[1] : scriptString;

switch (event) {
	case "deploy":
		new Deploy();
		break;
	case "create":
		new VueCreator();
		break;
	case "store":
		new Storage({
			filePath: "src/temp/",
			componentName: scriptsArray.length > 1 ? scriptsArray[0] : scriptString,
			content: scriptsArray.length > 1 ? scriptsArray[1] : {id: 0, name: "test"}
		});
		break;
	default:
		console.log(chalk.red("请输入正确的指令！"));
}
